﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KSUNO_EMS.Models;

namespace KSUNO_EMS.Controllers
{
    public class SampleController : Controller
    {
        //
        // GET: /Sample/

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ProperJsonResult FakeSave(string field1, string field2)
        {
            //try
            //{
            //    using (Models.PennEmsEntities db = new PennEmsEntities())
            //    {
            //        var employee = new Employee();
            //        employee.FirstName = field1;
            //        employee.LastName = field2;
            //        db.Employees.Add(employee);
            //        db.SaveChanges();
            //    }
            //}
            //catch (DbEntityValidationException ex)
            //{

            //    throw;
            //}

            return new ProperJsonResult() { Data = new AjaxResult(true, new { Field1 = field1, Field2 = field2 }) };
        }

        [HttpPost]
        public void Upload()
        {
            var request = Request;
            byte[] data;
            var result = Uploader.GetFile(Request, out data);
            System.IO.File.WriteAllBytes(Server.MapPath("~/" + result.filename), data);
        }
    }
}
